package com.newhis.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

/**
 * @author maojiayang
 * @description
 * @time 2022/09/06 15:37
 */
public class PatternUtils {


    /**
     * url判定
     *
     * @param patternPathList
     * @param requestPath
     * @return
     */
    public static boolean matchList(String[] patternPathList, String requestPath) {
        Boolean result = false;
        if (patternPathList != null && patternPathList.length > 0) {
            for (String patternPath : patternPathList) {
                boolean matchResult = match(patternPath, requestPath);
                if (matchResult) {
                    result = true;
                    continue;
                }
            }

        }
        return result;
    }

    /**
     * 匹配url
     *
     * @param patternPath 模糊匹配表达式
     * @param requestPath 待匹配的url
     * @return
     */
    public static boolean match(String patternPath, String requestPath) {
        if (StringUtils.isEmpty(patternPath) || StringUtils.isEmpty(requestPath)) {
            return false;
        }
        PathMatcher matcher = new AntPathMatcher();
        return matcher.match(patternPath, requestPath);
    }
}
